package hotLeetcode;

import java.util.ArrayList;
import java.util.List;

public class H78Leetcode {
    public List<List<Integer>> subsets(int[] nums) {
        List<List<Integer>> res = new ArrayList<>();
        List<Integer> path = new ArrayList<>();
        dfs(nums, res, path,0);
        return res;

    }


    private void dfs(int[] nums, List<List<Integer>> res, List<Integer> path , int startIndex) {

        res.add(new ArrayList<>(path));
        //结束条件
        if (startIndex >= nums.length) return;
        for (int i = startIndex; i < nums.length; i++) {
            path.add(nums[i]);
            //递归
            dfs(nums, res, path, i + 1);
            //回溯
            path.remove(path.size() - 1);



        }


    }

    public static void main(String[] args) {
        int[] arr = {1, 2, 3};
        H78Leetcode h78Leetcode = new H78Leetcode();
        h78Leetcode.subsets(arr);
    }
}
